home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00031_Slider Class.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  1.7 KB  |  64 lines

  1. property constrainChan, constrainPixels, maxChoice, minPos, sliderSprite, currentChoice, increment, slideLoc, numberSprite, totalSprite, playButton, pauseButton, reverseButton
  2. global gActorList
  3.  
  4. on birth me, constrChan, firstButChan, maxNum
  5.   set maxChoice to maxNum
  6.   set constrainChan to constrChan
  7.   set sliderSprite to firstButChan
  8.   set reverseButton to firstButChan + 1
  9.   set playButton to firstButChan + 2
  10.   set pauseButton to firstButChan + 3
  11.   set constrainPixels to the right of sprite constrainChan - the left of sprite constrainChan
  12.   set minPos to the left of sprite constrainChan
  13.   repeat with channel in [sliderSprite, reverseButton, playButton, pauseButton]
  14.     puppetSprite(channel, 1)
  15.   end repeat
  16.   set currentChoice to 1
  17.   set increment to 1.0 * constrainPixels / (maxChoice - 1)
  18.   set the constraint of sprite sliderSprite to constrainChan
  19.   return me
  20. end
  21.  
  22. on updateSlider me
  23.   set the locH of sprite the clickOn to the mouseH
  24.   set slideLoc to the locH of sprite the clickOn
  25.   set currentPos to slideLoc - minPos
  26.   set currentChoice to integer(1.0 * currentPos / increment) + 1
  27. end
  28.  
  29. on snap me
  30.   if currentChoice = maxChoice then
  31.     snapToTop(me)
  32.   else
  33.     if currentChoice = 1 then
  34.       snapToBottom(me)
  35.     else
  36.       snapInMiddle(me)
  37.     end if
  38.   end if
  39.   updateStage()
  40. end
  41.  
  42. on snapToBottom me
  43.   set slideLoc to minPos
  44.   moveSlider(me)
  45. end
  46.  
  47. on snapToTop me
  48.   set slideLoc to minPos + constrainPixels
  49.   moveSlider(me)
  50. end
  51.  
  52. on snapInMiddle me
  53.   set slideLoc to minPos + integer((currentChoice - 1) * increment)
  54.   moveSlider(me)
  55. end
  56.  
  57. on moveSlider me
  58.   set the locH of sprite sliderSprite to slideLoc
  59. end
  60.  
  61. on dispose me
  62.   set the constraint of sprite sliderSprite to 0
  63. end
  64.